package com.zdxlz.fcmp.business.controller.local;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdxlz.fcmp.business.dto.KmsConfigDto;
import com.zdxlz.fcmp.business.entity.KmsConfigEntity;
import com.zdxlz.fcmp.business.service.IKmsConfigService;
import com.zdxlz.fcmp.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import static com.zdxlz.fcmp.common.core.constant.CommonConstants.*;

/**
 * 量子密码资源配置表 前端控制器
 *
 * @author: aman
 * @since 2025-02-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/v1/kms")
public class KmsConfigController {
    private IKmsConfigService kmsConfigService;

    @GetMapping
    public R getList(@ParameterObject Page<KmsConfigEntity> page, @ParameterObject KmsConfigDto kmsConfigDto) {
        return R.ok(kmsConfigService.getList(page, kmsConfigDto), OPERATION_SUCCESS);
    }

    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        return R.ok(kmsConfigService.getById(id), OPERATION_SUCCESS);
    }

    @PostMapping
    public R create(@RequestBody @Validated KmsConfigEntity entity) {
        return R.ok(kmsConfigService.createKmsConfig(entity), CREATE_SUCCESS);
    }

    @PutMapping("/{id}")
    public R update(@PathVariable Integer id, @RequestBody @Validated KmsConfigEntity entity) {
        entity.setId(id);
        return R.ok(kmsConfigService.updateKmsConfig(entity), UPDATE_SUCCESS);
    }

    @DeleteMapping
    public R delete(@RequestBody List<Integer> ids) {
        return R.ok(kmsConfigService.removeBatchByIds(ids), DELETE_SUCCESS);
    }
}
